#include <iostream>
#include "stuinfo.hpp"
#include <cstring>
using namespace std;
//void showstu(int n);
char temp[20];
double temp1[3],temp2=0;

void inputstu(int n)
{
    stuinfo stu[n];
    for (int  information = 0; information < n; information++)
    {
        
        cin.get();
        cout << "Student " << information << "'s name:";
        cin.getline(stu[information].name,20);
        //cout << "Student " << n << "'s sores:"<<endl; 
        cout << "Student " << information << "'s scores:";
        for(int i = 0; i <= 2; i++){
            cin >> stu[information].score[i];  
        }
        // for(int i = 0; i <= 2; i++){
        //     cout << stu[information].score[i]; 
        // }
    }   
    cout << "The information of "<< n << "students you input are :"<<endl;
    for (int information = 0 ; information < n ; information++)
    {
        
        cout << "Student " << information << "'s name:"<< stu[information].name << ", scores:";
        for(int i = 0; i <= 2; i++)
        {
        cout << stu[information].score[i]<< " ";  
        }
        cout << endl;
    }

    cout << "\nThe descending order of the students:"<<endl;
    for (int information = 0 ; information < n ; information++)
    {
        for (int count = 0; count <=2 ; count++)
        {
        stu[information].ave = stu[information].ave + stu[information].score[count];
        }
        stu[information].ave= stu[information].ave/3;
    }

    for (int i = 0 ; i < n -1; i++)
    {
        for (int information = 0 ; information < n-1-i ; information++)
        {
            if(stu[information].ave < stu[information+1].ave)
            {
                strcpy(temp,stu[information].name);
                for(int j=0 ; j <= 2 ; j++)
                {
                    temp1[j]=stu[information].score[j];
                }
                temp2 = stu[information].ave;

                strcpy(stu[information].name,stu[information+1].name);
                for(int j=0 ; j <= 2 ; j++)
                {
                    stu[information].score[j]=stu[information+1].score[j];
                }
                stu[information].ave=stu[information+1].ave;
                
                strcpy(stu[information+1].name,temp);
                for(int j=0 ; j <= 2 ; j++)
                {
                    stu[information+1].score[j] = temp1[j];
                }
                stu[information+1].ave=temp2;
            }
        }
    }
   for (int information = 0 ; information < n ; information++)
    {
     cout << "Student " << information << "'s name:"<< stu[information].name << ", scores:";
        for(int i = 0; i <= 2; i++)
        {
        cout << stu[information].score[i]<< " ";  
        }
        
        cout <<" ave : "<<stu[information].ave<< endl;
    }
    for (int information = 0 ; information < n ; information++)
    {
        cin.get();
        cout << "Please input the name you want to find: ";
        cin.getline(temp,20);
        if(temp == stu[information].name)
        {
            cout << temp << "is in the students list" << endl;
        }
        else
        {
            cout << temp << "is not in the students list" << endl;

        }
    }

}

// void showstu(stuinfo stu[],int n) 
// {   
    


// }

// void sortst(int n)
// {
//     stuinfo stu[n];


// }
